import random
import time
from life_game import core

ROWS = 50
COLS = 50
CELL_SIZE = 15
HEIGHT = (ROWS * CELL_SIZE)
WIDTH  = (COLS * CELL_SIZE)

BACK_COLOR = (0, 0, 127)
CELL_COLOR = (0, 200, 0)

g = core.Game(ROWS, COLS)

def roll_color():
    return (random.randint(100, 200), random.randint(100, 200), random.randint(100, 200))

def draw_cell(r, c):
    cx = CELL_SIZE * c
    cy = CELL_SIZE * r
    cell_rect = Rect((cx, cy), (CELL_SIZE, CELL_SIZE))
    screen.draw.filled_rect(cell_rect, roll_color())
    return 1

def draw():
    screen.fill(BACK_COLOR)
    g.render(draw_cell)
      
def update():
    g.update()
    time.sleep(0.5)

def on_mouse_down(pos, button):
    r = pos[1] // CELL_SIZE
    c = pos[0] // CELL_SIZE
    g.force_active_cell((r, c))
